package com.hlt.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.hlt.entity.Shopping_car;
import com.hlt.service.UserService;

/**
 * @author Hu_liantian
 * @date 2020/7/21
 */
@Controller
public class UserController {
		
		@Autowired
		UserService us;
		
		@RequestMapping("/add")
		public ModelAndView login(HttpServletRequest req,  String cuser, String cde,
				String cname, String ctype, String cnumber, String caim, String cneed)
				throws ServletException, IOException {
			ModelAndView mv = new ModelAndView();
			Shopping_car u = us.add(cuser, cde,
					 cname,  ctype,  cnumber,  caim,  cneed);
			System.out.println(u);
			if (u != null) {
				req.getSession().setAttribute("u", u);
				mv.setViewName("Access");
			} else {
				mv.addObject("errMsg", "失败，重新输入");
				mv.setViewName("Add");
			}
			return mv;
		}
		
		@RequestMapping("/Reg")
		public ModelAndView reg(Shopping_car u) {
			ModelAndView mv = new ModelAndView();
			int i = us.reg(u);
			if (i > 0) {
				mv.addObject("regMsg", "成功！");
				mv.setViewName("Add");
			} else {
				mv.addObject("regMsg", "请重新添加");
				mv.setViewName("Reg");
			}
			return mv;
		}
		
}